Skip to content

Upstream changes from perf-event-open-sys2#42

Merged
jimblandy merged 15 commits intojimblandy:masterfrom
Phantomical:upstream-sys-changes
Apr 9, 2025
Merged

Upstream changes from perf-event-open-sys2#42
jimblandy merged 15 commits intojimblandy:masterfrom
Phantomical:upstream-sys-changes

Conversation

@Phantomical
Copy link
Collaborator

This is a (mostly) straight upstream of the various changes I have made to perf-event-open-sys2. These are few enough that I figure I can upstream them all at once. I don't intend to do this with changes to the perf-event crate, which are more involved.

Here's the list of relevant changes:

This isn't a straight upstream. I have made a few small tweaks where I think appropriate. These tweaks are:

  • I don't use the memoffset crate anymore. std::mem::offset_of! has been stable for long enough now that it is fine to just use it.
  • src/version no longer includes an extra period at the end, this is instead added in the docs via concat!
  • I've added a note about how we don't exactly follow the output of cargo semver-checks for versioning.
  • I've added a new field to the deref stack for perf_event_open, since the aux_action field was turned into an unnamed union in the kernel headers. I have not handled the unnamed bitfield in the union yet, I'll do that in a follow-up PR.

Otherwise the main theme of these changes (other than the regenerate script) is this: if it is not a breaking change in the C header, that should generally not be a breaking change for the bindings here. In practice I found that major version bumps in perf-event-open-sys2 required a corresponding major version bump in perf-event2, which is a bit of a pain for everyone involved.

There are some tradeoffs here. It is no longer possible to use the struct update syntax with perf_event_attr. That is basically the only real loss though, and I think that is a fair price to pay for avoiding making a breaking release every time somebody makes an update to perf_event_attr on the kernel side.

None of this is final though! We can make changes (either here or in a follow up) to better address certain use cases. I'm happy to hear feedback on this :)

This commit contains two main changes:
- regenerate.sh has been rewritten to generate bindings from a local
  copy of the linux kernel source instead of using the headers installed
  on the current system.
- The bindings for x86 and arm64 have been regenerated from kernel
  version 6.2.10.

The benefit of this change is that it is easier to update the generated
bindings. It is not necessary to get a live install of whatever the
newest kernel version is to generate bindings for a new kernel version.
This is just barely doable with x86_64 and aarch64 but is rather
impractical for any one person to do once we think about potentially
bringing in other architectures. After this change, all that needs to be
done is update regenerate.sh with the new kernel verison and run it.
@Phantomical Phantomical force-pushed the upstream-sys-changes branch from 9fc2db1 to 9731b10 Compare April 5, 2025 23:25
@Phantomical Phantomical requested a review from jimblandy April 5, 2025 23:26
@jimblandy
Copy link
Owner

This looks amazing.

As I've said elsewhere, we definitely want the changes for regenerating the bindings directly from the kernel sources. And certainly our bindings should not include non-perf types and constants.

I am not sure about the #[non_exhaustive] changes. Would it be possible to split those out into a separate PR so we can talk about the problems we're trying to solve with it?

I'd also like the chance to understand the anonymous union trick a little better. Would it be possible to split that out into a separate PR as well?

The asm/perf_event.h includes definitions for the registers for the
current architecture. If you want to tell perf_event_open to sample CPU
registers then you need these definitions.
It is not necessary since we can generically cast to the right value by
doing `ioctl as _`.
The current way of generating bindings via bindgen creates entries for
any type or constant that is reachable when including the headers listed
in wrapper.h. In addition to the perf-related structs we care about,
this includes:
- A variety of unrelated kernel API types
- A bunch of constants used as implementation details for making ioctls
- A constant for every single syscall number
- ... and more besides

There is no reason to include these in the generated bindings. Once
present, however, removing or changing them becomes a breaking change.
This is a one-shot change that changes the generation to only keep the
relevant structs.

This is a breaking change and would require a perf-event-open-sys2
v6.0.0.
@Phantomical Phantomical force-pushed the upstream-sys-changes branch from 9731b10 to a191795 Compare April 6, 2025 18:46
@Phantomical Phantomical force-pushed the upstream-sys-changes branch from a191795 to 58b96ad Compare April 6, 2025 18:48
@Phantomical
Copy link
Collaborator Author

Sure. I've stripped out those commits. Once this one is merged I'll make more PRs with those changes.

@jimblandy
Copy link
Owner

These files seem to be generated by an older version of bindgen. Could you try regenerating them with 0.71.1?

@Phantomical
Copy link
Collaborator Author

Phantomical commented Apr 9, 2025

Done. To be honest, I was not expecting it to have that many changes going from 0.69 to 0.71.

@jimblandy jimblandy merged commit d4f1127 into jimblandy:master Apr 9, 2025
5 checks passed
@jimblandy
Copy link
Owner

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants